function LoginValid(){
    var Utel=$('input[name=Utel]').val(),
        Upass=$('input[name=Upass]').val(),
        data;
    if(!Utel){
        layer.msg('请输入电话号码',{icon: 2,time:1000});
        $('input[name=Utel]').focus();
        return false;
    }
    if(!Upass){
        layer.msg('请输入登录密码',{icon: 2,time:1000});
        $('input[name=Upass]').focus();
        return false;
    }
    data={utel:Utel,upass:Upass};
    $.ajax({
        type:'post',
        dataType:'json',
        url : '/login.html',
        data:  data,
        success: function(json){
            if(json.status==1){
                var index = layer.load(1, {
                    shade: [0.1,'#fff']
                });
                setTimeout(function(){window.location.href='/choosetype.html';},1000);
            }else{
                layer.msg(json.msg,{icon: 2,time:1000});
            }
        },
        error:function (){
            layer.msg('服务器繁忙，请刷新页面后重试',{icon: 5,area: ['', '15%'],time:1000});
        }
    });
}
function ChooseSub(obj,status){
    if(status==1){
        if(parseInt($('.practice').attr('id'))<3){
            $(obj).attr('class','home-icon4 home-black');
            $(obj).attr('onclick','ChooseSub(this,2)');
            $('.practice').attr('id', parseInt($('.practice').attr('id'))+1);
        }else{
            layer.msg('只能选择三套题哦',{icon: 7,time:1000})
            return false;
        }
    }
    if(status==2){
        if(parseInt($('.practice').attr('id'))>=0){
            $(obj).attr('class','home-icon4');
            $(obj).attr('onclick','ChooseSub(this,1)');
            $('.practice').attr('id', parseInt($('.practice').attr('id'))-1);
        }else{
            layer.msg('请正规操作',{icon: 7,time:1000})
            return false;
        }
    }
    var data={id:$(obj).attr('id'),status:status};
    $.ajax({
        type:'post',
        dataType:'json',
        url : '/5-153710252635.html',
        data:data,
    });
}
function Practice(obj,status){
    var key=$(obj).attr('id');
    if(key==0){
        layer.msg('请选择套题',{icon: 7,time:1000});
        return false;
    }
    if(status==1){
        location.href='/s-16'+key+'158490127-1-t.html';
    }
    if(status==2){
        location.href='/s-16015849'+key+'127-1-t.html';
    }
}
function ShowAnswer(){
    $('.exam-answer').attr('style','display:');
}
function Judge(key,key2,status){
    var data={key:key,key2:key2,status:status},
        ValidAutoPage=$('#Auto').attr('class'),
        ValidAutoSPage=$('#SAuto').attr('class'),
        ValidAutoSePage=$('#SeAuto').attr('class'),
        DaAn=GetSubjectAnswer(status,2),
        Ssid=$('input[name=nextssid]').val();
    if(key2!=status) $('#ErrorId').attr('onclick','ErrorReset(1)');
    $.ajax({
        type:'post',
        dataType:'json',
        url : '/s-160158490127-1-t.html',
        data:  data,
        success: function(json){
            if(json.status==1){
                if(ValidAutoPage=='OpenAuto'){
                    if(Ssid!=0){
                        LocationSsid(Ssid);
                    }else{
                        layer.msg('这是最后一道题了哦',{icon: 6,time:1000});
                        $('#'+key).children('a').html(parseInt($('#'+key).children('a').text())+'<br>'+DaAn);
                        if(key2==status){
                            $('#'+key).attr('class','exam-i exam-ok');
                        }else{
                            $('#'+key).attr('class','exam-i exam-error');
                        }
                    }
                }else{
                    if(ValidAutoSPage=='OpenAuto'){
                        if(key2==status){
                            if(Ssid!=0){
                                LocationSsid(Ssid);
                            }else{
                                layer.msg('这是最后一道题了哦',{icon: 6,time:1000});
                                $('#'+key).children('a').html(parseInt($('#'+key).children('a').text())+'<br>'+DaAn);
                                $('#'+key).attr('class','exam-i exam-ok');
                            }
                        }else{
                            if(Ssid==0){
                                layer.msg('这是最后一道题了哦',{icon: 6,time:1000});
                            }
                            $('.exam-select').html("<div class'exam-answe'>您的答案：<span class='myanswer'>"+DaAn+"</span></div>");
                            $('#'+key).children('a').html(parseInt($('#'+key).children('a').text())+'<br>'+DaAn);
                            $('#'+key).attr('class','exam-i exam-error');
                        }
                    }else{
                        if(ValidAutoSePage=='OpenAuto'){
                            if(key2!=status){
                                OpenSpeaks();
                            }
                        }
                        if(Ssid==0){
                            layer.msg('这是最后一道题了哦',{icon: 6,time:1000});
                        }
                        $('.exam-select').html("<div class'exam-answe'>您的答案：<span class='myanswer'>"+DaAn+"</span></div>");
                        $('#'+key).children('a').html(parseInt($('#'+key).children('a').text())+'<br>'+DaAn);
                        if(key2==status){
                            $('#'+key).attr('class','exam-i exam-ok');
                        }else{
                            $('#'+key).attr('class','exam-i exam-error');
                        }
                    }
                }
            }else{
                layer.msg(json.msg,{icon: 2,time:1000});
                if(json.status==2) setTimeout(function(){top.location.href='/login.html';},2000)
            }
        },
    })
}
function RadioCheck(key,key2,status){
    var data={key:key,key2:key2,status:status},
        ValidAutoPage=$('#Auto').attr('class'),
        ValidAutoSPage=$('#SAuto').attr('class'),
        ValidAutoSePage=$('#SeAuto').attr('class'),
        DaAn=GetSubjectAnswer(status,1),
        Ssid=$('input[name=nextssid]').val();
    if(key2!=status) $('#ErrorId').attr('onclick','ErrorReset(1)');
    $.ajax({
        type:'post',
        dataType:'json',
        url : '/s-160158490127-1-t.html',
        data:  data,
        success: function(json){
            if(json.status==1){
                if(ValidAutoPage=='OpenAuto'){
                    if(Ssid!=0){
                        LocationSsid(Ssid);
                    }else{
                        layer.msg('这是最后一道题了哦',{icon: 6,time:1000});
                        $('#'+key).children('a').html(parseInt($('#'+key).children('a').text())+'<br>'+DaAn);
                        if(key2==status){
                            $('#'+key).attr('class','exam-i exam-ok');
                        }else{
                            $('#'+key).attr('class','exam-i exam-error');
                        }
                    }
                }else{
                    if(ValidAutoSPage=='OpenAuto'){
                        if(key2==status){
                            if(Ssid!=0){
                                LocationSsid(Ssid);
                            }else{
                                layer.msg('这是最后一道题了哦',{icon: 6,time:1000});
                                $('#'+key).children('a').html(parseInt($('#'+key).children('a').text())+'<br>'+DaAn);
                                $('#'+key).attr('class','exam-i exam-ok');
                            }
                        }else{
                            if(Ssid==0){
                                layer.msg('这是最后一道题了哦',{icon: 6,time:1000});
                            }
                            $('.exam-select').html("<div class'exam-answe'>您的答案：<span class='myanswer'>"+DaAn+"</span></div>");
                            $('#'+key).children('a').html(parseInt($('#'+key).children('a').text())+'<br>'+DaAn);
                            $('#'+key).attr('class','exam-i exam-error');
                        }
                    }else{
                        if(ValidAutoSePage=='OpenAuto'){
                            if(key2!=status){
                                OpenSpeaks();
                            }
                        }
                        if(Ssid==0){
                            layer.msg('这是最后一道题了哦',{icon: 6,time:1000});
                        }
                        $('.exam-select').html("<div class'exam-answe'>您的答案：<span class='myanswer'>"+DaAn+"</span></div>");
                        $('#'+key).children('a').html(parseInt($('#'+key).children('a').text())+'<br>'+DaAn);
                        if(key2==status){
                            $('#'+key).attr('class','exam-i exam-ok');
                        }else{
                            $('#'+key).attr('class','exam-i exam-error');
                        }
                    }
                }
            }else{
                layer.msg(json.msg,{icon: 2,time:1000});
                if(json.status==2) setTimeout(function(){top.location.href='/login.html';},2000)
            }
        },
    })
}
function BoxCheck(key,key2,obj){
    var status= $(obj).attr('id') ? $(obj).attr('id') : 0,
        ValidAutoPage=$('#Auto').attr('class'),
        ValidAutoSPage=$('#SAuto').attr('class'),
        ValidAutoSePage=$('#SeAuto').attr('class'),
        DaAn,data,
        Ssid=$('input[name=nextssid]').val();
    if(status==0){
        layer.msg('请选择答案后再提交',{icon: 2,time:1000});
        return false;
    }else{
        $(obj).attr('id',0);
    }
    ValidAutoPage=$('#Auto').attr('class'),
        ValidAutoSPage=$('#SAuto').attr('class'),
        ValidAutoSePage=$('#SeAuto').attr('class'),
        DaAn=GetSubjectAnswer(parseInt(status),1),
        data={key:key,key2:key2,status:status},
        Ssid=$('input[name=nextssid]').val();
    if(key2!=status) $('#ErrorId').attr('onclick','ErrorReset(1)');
    $.ajax({
        type:'post',
        dataType:'json',
        url : '/s-160158490127-1-t.html',
        data:  data,
        success: function(json){
            if(json.status==1){
                if(ValidAutoPage=='OpenAuto'){
                    if(Ssid!=0){
                        LocationSsid(Ssid);
                    }else{
                        layer.msg('这是最后一道题了哦',{icon: 6,time:1000});
                        $('#'+key).children('a').html(parseInt($('#'+key).children('a').text())+'<br>'+DaAn);
                        if(key2==status){
                            $('#'+key).attr('class','exam-i exam-ok');
                        }else{
                            $('#'+key).attr('class','exam-i exam-error');
                        }
                    }
                }else{
                    if(ValidAutoSPage=='OpenAuto'){
                        if(key2==status){
                            if(Ssid!=0){
                                LocationSsid(Ssid);
                            }else{
                                layer.msg('这是最后一道题了哦',{icon: 6,time:1000});
                                $('#'+key).children('a').html(parseInt($('#'+key).children('a').text())+'<br>'+DaAn);
                                $('#'+key).attr('class','exam-i exam-ok');
                            }
                        }else{
                            if(Ssid==0){
                                layer.msg('这是最后一道题了哦',{icon: 6,time:1000});
                            }
                            $('.exam-select').html("<div class'exam-answe'>您的答案：<span class='myanswer'>"+DaAn+"</span></div>");
                            $('#'+key).children('a').html(parseInt($('#'+key).children('a').text())+'<br>'+DaAn);
                            $('#'+key).attr('class','exam-i exam-error');
                        }
                    }else{
                        if(ValidAutoSePage=='OpenAuto'){
                            if(key2!=status){
                                OpenSpeaks();
                            }
                        }
                        if(Ssid==0){
                            layer.msg('这是最后一道题了哦',{icon: 6,time:1000});
                        }
                        $('.exam-select').html("<div class'exam-answe'>您的答案：<span class='myanswer'>"+DaAn+"</span></div>");
                        $('#'+key).children('a').html(parseInt($('#'+key).children('a').text())+'<br>'+DaAn);
                        if(key2==status){
                            $('#'+key).attr('class','exam-i exam-ok');
                        }else{
                            $('#'+key).attr('class','exam-i exam-error');
                        }
                    }
                }
            }else{
                layer.msg(json.msg,{icon: 2,time:1000});
                if(json.status==2) setTimeout(function(){top.location.href='/login.html';},2000)
            }
        },
    })
}
function SkipThisSub(key,status){
    if(status==0){
        layer.confirm('您确定要跳过此题吗', {
            btn: ['确定','取消'] //按钮
        }, function(){
            var data={key:key,status:status};
            $.ajax({
                type:'post',
                dataType:'json',
                url : '/s-160158490127-1-t.html',
                data:  data,
                success: function(json){
                    window.location.reload();
                },
            })
        }, function(){
            layer.msg('取消操作成功', {icon: 1,area: ['', '15%'],time:1000});
        });
    }else{
        window.location.reload();
    }
}
function CheckStatus(obj,key,status) {
    var CheckKey = $('.cs-button').attr('id') ? $('.cs-button').attr('id') : 0,
        NowSubject = parseInt($('.text-red').children('a').text());
    if(status==1){
        $('.cs-button').attr('id',parseInt(key)+parseInt(CheckKey));
        $('#CheckAuto').val(parseInt(key)+parseInt(CheckKey));
        $(obj).attr('onclick','CheckStatus(this,'+key+',2)');
        $(obj).attr('class','an-btn an-btn-check');
        NowSubject = NowSubject+'<br />'+GetSubjectAnswer(parseInt(key)+parseInt(CheckKey),1);
    }
    if(status==2){
        $('.cs-button').attr('id',parseInt(CheckKey)-parseInt(key));
        $('#CheckAuto').val(parseInt(CheckKey)-parseInt(key));
        $(obj).attr('onclick','CheckStatus(this,'+key+',1)');
        $(obj).attr('class','an-btn');
        NowSubject = NowSubject+'<br />'+GetSubjectAnswer(parseInt(CheckKey)-parseInt(key),1);
    }
    $('.text-red').children('a').html(NowSubject);
}
function AutoPage(obj,status) {
    var data;
    if(status==1){
        $(obj).attr('onclick','AutoPage(this,2)');
        $(obj).attr('class','an-btn-check');
        $('#Auto').attr('class','OpenAuto');
        $('#SAuto').attr('class','CloseAuto');
        $('#SeAuto').attr('class','CloseAuto');
        $(obj).next().attr('class','');
        $(obj).next().attr('onclick','AutoSPage(this,1)');
        $(obj).prev().attr('class','');
        $(obj).prev().attr('onclick','AutoSePage(this,1)');
        data={AutoPage:2};
    }
    if(status==2){
        $(obj).attr('class','');
        $(obj).attr('onclick','AutoPage(this,1)');
        $('#Auto').attr('class','CloseAuto');
        data={AutoPage:1};
    }
    $.ajax({
        type:'post',
        dataType:'json',
        url : '/autopage.html',
        data:  data,
    });
}
function AutoSPage(obj,status) {
    var data;
    if(status==1){
        $(obj).attr('onclick','AutoSPage(this,2)');
        $(obj).attr('class','an-btn-check');
        $('#SAuto').attr('class','OpenAuto');
        $('#Auto').attr('class','CloseAuto');
        $('#SeAuto').attr('class','CloseAuto');
        $(obj).prev().attr('class','');
        $(obj).prev().attr('onclick','AutoPage(this,1)');
        $(obj).prev().prev().attr('class','');
        $(obj).prev().prev().attr('onclick','AutoSePage(this,1)');
        data={AutoPage:3};
    }
    if(status==2){
        $(obj).attr('class','');
        $(obj).attr('onclick','AutoSPage(this,1)');
        $('#SAuto').attr('class','CloseAuto');
        data={AutoPage:1};
    }
    $.ajax({
        type:'post',
        dataType:'json',
        url : '/autopage.html',
        data:  data,
    });
}
function AutoSePage(obj,status) {
    var data;
    if(status==1){
        $(obj).attr('onclick','AutoSePage(this,2)');
        $(obj).attr('class','an-btn-check');
        $('#SeAuto').attr('class','OpenAuto');
        $('#Auto').attr('class','CloseAuto');
        $('#SAuto').attr('class','CloseAuto');
        $(obj).next().attr('class','');
        $(obj).next().attr('onclick','AutoPage(this,1)');
        $(obj).next().next().attr('class','');
        $(obj).next().next().attr('onclick','AutoSPage(this,1)');
        data={AutoPage:5};
    }
    if(status==2){
        $(obj).attr('class','');
        $(obj).attr('onclick','AutoSePage(this,1)');
        $('#SeAuto').attr('class','CloseAuto');
        data={AutoPage:1};
    }
    $.ajax({
        type:'post',
        dataType:'json',
        url : '/autopage.html',
        data:  data,
    });
}
function AutoSpPage(obj,status) {
    var data;
    if(status==1){
        $(obj).attr('onclick','AutoSpPage(this,2)');
        $(obj).attr('class','an-btn-check');
        $('#SpAuto').attr('class','OpenAuto');
        data={AutoSpPage:6};
        OpenSpeaks();
    }
    if(status==2){
        $(obj).attr('class','');
        $(obj).attr('onclick','AutoSpPage(this,1)');
        $('#SpAuto').attr('class','CloseAuto');
        data={AutoSpPage:1};
    }
    $.ajax({
        type:'post',
        dataType:'json',
        url : '/autopage.html',
        data:  data,
    });
}
function AutoShowAns(obj,status){
    var data;
    if(status==1){
        $(obj).attr('onclick','AutoShowAns(this,2)');
        $(obj).attr('class','an-btn-check');
        $('#ShAuto').attr('class','OpenAuto');
        $('.exam-answer').attr('style','display:;');
    }
    if(status==2){
        $(obj).attr('class','');
        $(obj).attr('onclick','AutoShowAns(this,1)');
        $('#ShAuto').attr('class','CloseAuto');
        $('.exam-answer').attr('style','display:none;');
    }
    data={status:status};
    $.ajax({
        type:'get',
        dataType:'json',
        url : '/autopage.html',
        data:  data,
    });
}
function CheckMedia(){
    var myAudio = document.getElementById('audio');
    audio.play();//开始播放
}
function EndTest(status){
    if(status==1){
        layer.confirm('请确定是否要交卷', {
            btn: ['确定','取消'] //按钮
        }, function(){
            var index = layer.load(1, {
                shade: [0.1,'#fff']
            });
            $.ajax({
                type:'post',
                dataType:'json',
                url : '/testresult.html',
                success: function(json){
                    if(json.status==2){
                        layer.msg(json.msg,{icon: 2,time:1000});
                        setTimeout(function(){top.location.href='/login.html';},2000)
                    }else{
                        window.location.reload();
                    }
                },
            })
        }, function(){
            layer.msg('取消操作成功', {icon: 1,area: ['', '15%'],time:1000});
        });
    }
    if(status==2){
        layer.msg('您已经交过卷了',{icon: 2,time:1000});
    }
    if(status==3){
        var index = layer.load(1, {
            shade: [0.1,'#fff']
        });
        $.ajax({
            type:'post',
            dataType:'json',
            url : '/testresult.html',
            success: function(json){
                window.location.reload();
            },
        })
    }
}
function OpenSpeaks(){
    var audio = document.getElementById("musicpath");
    audio.play();
}
function ErrorReset(status){
    if(status==1 || status==3){
        layer.confirm('即将进入错题二次重做，请确认', {
            btn: ['确定','取消'] //按钮
        }, function(){
            var index = layer.load(1, {
                shade: [0.1,'#fff']
            });
            $.ajax({
                type:'post',
                dataType:'json',
                url : '/erroreset.html',
                success: function(json){
                    if(json.status==2){
                        layer.msg(json.msg,{icon: 2,time:1000});
                        setTimeout(function(){top.location.href='/login.html';},2000)
                    }else{
                        if(status==1){
                            window.location.href='/s-160158490127-1-t.html';
                        }else{
                            parent.location.href='/s-160158490127-1-t.html';
                        }
                    }
                },
            })
        }, function(){
            layer.msg('取消操作成功', {icon: 1,area: ['', '15%'],time:1000});
        });
    }else{
        layer.msg('您没有做错题哦',{icon: 6,time:1000});
    }
}
function MyError(){
    layer.open({
        type: 2,
        title: '我的错题',
        area: ['300px', '200px'],
        fixed: false,
        maxmin: true,
        content: "/erroreset.html"
    });
}
function errReset(status){
    if(status==1){
        $.ajax({
            type:'post',
            dataType:'json',
            url : '/makerror.html',
            success: function(json){
                if(json.status==2){
                    layer.msg(json.msg,{icon: 2,time:1000});
                    setTimeout(function(){top.location.href='/login.html';},2000)
                }else{
                    parent.location.href='/s-160158490127-1-t.html';
                }
            },
        })
    }
    if(status==2){
        $.ajax({
            type:'get',
            dataType:'json',
            url : '/makerror.html',
            success: function(json){
                if(json.status==2){
                    layer.msg(json.msg,{icon: 2,time:1000});
                    setTimeout(function(){top.location.href='/login.html';},2000)
                }else{
                    window.location.reload();
                }
            },
        })
    }
    if(status==3){
        layer.msg('您没有错题哦',{icon: 6,time:1000});
    }
}
function MyEditPass(){
    layer.open({
        type: 2,
        title: '修改密码',
        area: ['500px', '300px'],
        fixed: false,
        maxmin: true,
        content: "/editpass.html"
    });
}
function ContPlay(){
    layer.confirm('请确认是否继续做题', {
        btn: ['确定','取消'] //按钮
    }, function(){
        var index = layer.load(1, {
            shade: [0.1,'#fff']
        });
        $.ajax({
            type:'post',
            dataType:'json',
            url : '/contplay.html',
            success: function(json){
                if(json.status==1){
                    window.location.href='/s-160158490127-1-t.html?ssid='+json.msg+'#'+json.msg;
                }else{
                    layer.msg(json.msg,{icon: 2,time:1000});
                    setTimeout(function(){top.location.href='/login.html';},2000)
                }
            },
        })
    }, function(){
        layer.msg('取消操作成功', {icon: 1,area: ['', '15%'],time:1000});
    });
}
function LocationSsid(key){
    var container = $('.exam3-1'),
        scrollTo = $('#'+key);
    container.scrollTop(
        scrollTo.offset().top - container.offset().top + container.scrollTop()-83
    );
    container.animate({
        scrollTop: scrollTo.offset().top - container.offset().top + container.scrollTop()-83
    });
    var Cid = $('#CheckAuto').val() ? parseInt($('#CheckAuto').val()) : 0;
    if(Cid){
        var ssid = $('#CheckAuto').attr('sid') ? $('#CheckAuto').attr('sid') : 0,
            DaAn = $('#CheckAuto').attr('did') ? $('#CheckAuto').attr('did') : 0,
            data;
        if(ssid && DaAn){
            data={key:ssid,key2:DaAn,status:Cid},
                $.ajax({
                    type:'post',
                    dataType:'json',
                    url : '/s-160158490127-1-t.html',
                    data:  data
                })
        }
    }
    if(key){
        $.ajax({
            type:'post',
            dataType:'json',
            url : '/ajaxsub.html',
            data:'key='+key,
            success: function(json){
                if(json.status==1){
                    // window.location.href = '#'+key;
                    $('.exam2').html(json.SubHtml);
                    $('#musicpath').attr('src',json.musicpath);
                    $('#StrNum').html(json.StrNumHtml);
                    $('#PractRe').html(json.PractReHtml);
                    if($('#ShAuto').attr('class')=='OpenAuto'){
                        $('.exam-answer').attr('style','display:');
                    }
                    if($('#SpAuto').attr('class')=='OpenAuto'){
                        OpenSpeaks();
                    }
                }else{
                    layer.msg(json.msg,{icon: 2,time:1000});
                    if(json.status==2) setTimeout(function(){top.location.href='/login.html';},2000)
                }
            }
        })
    }
}